package cn.uexpo.lhz.service.impl;

import cn.uexpo.lhz.service.AuthorizedGitService;
import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.model.AuthCallback;
import me.zhyd.oauth.request.AuthGiteeRequest;
import me.zhyd.oauth.request.AuthRequest;
import me.zhyd.oauth.utils.AuthStateUtils;
import org.springframework.stereotype.Service;


import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author 小坏
 * @Date 2020/9/24 9:46
 * @Version 1.0
 * @program: 父工程 renren-cloud 万物起源之地
 */

@Service
public class AuthorizedGitServiceImpl implements AuthorizedGitService {
    public void renderAuth(HttpServletResponse response) throws IOException {
        AuthRequest authRequest = getAuthRequest();
        response.sendRedirect(authRequest.authorize(AuthStateUtils.createState()));
    }

    public Object login(AuthCallback callback) {
        AuthRequest authRequest = getAuthRequest();
        return authRequest.login(callback);
    }

    public AuthRequest getAuthRequest() {
        return new AuthGiteeRequest(AuthConfig.builder()
                .clientId("ebb324ec39aea6f33c145511d95d18ba14b3f1de6fc009b68d4a1ae7ab797889")
                .clientSecret("38ae15c154fae7ecc939f05b7ffcd0cae510b5862442c875e11a2fc884cbd776")
                .redirectUri("http://8zjft2.natappfree.cc/gitee/callback")
                .build());
    }
}
